<template>
  <div class="mod-log">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.operator" placeholder="操作人员" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="getDataList()">查询</el-button>
        <el-button type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%" @selection-change="selectionChangeHandle">
      <el-table-column type="selection" header-align="center" align="center" width="80"></el-table-column>
      <el-table-column prop="operator" header-align="center" align="center" width="150" label="操作人员"></el-table-column>
      <el-table-column prop="operation" header-align="center" align="center" width="180" label="执行任务"></el-table-column>
      <el-table-column prop="method" header-align="center" align="center" :show-overflow-tooltip="true" label="请求方法"></el-table-column>
      <el-table-column prop="params" header-align="center" align="center" :show-overflow-tooltip="true" label="请求参数"></el-table-column>
      <el-table-column prop="ipAddress" header-align="center" align="center" width="160" label="IP地址"></el-table-column>
      <el-table-column prop="createTime" header-align="center" align="center" width="160" label="创建时间">
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
      :current-page="dataForm.pageNum" :page-sizes="[10, 20, 50, 100]" :page-size="dataForm.pageSize" :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        dataForm: {
          operator: '',
          pageNum: 1,
          pageSize: 10
        },
        dataList: [],
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: []
      }
    },
    created () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/admin-interfaces/log/pageList'),
          method: 'post',
          data: this.dataForm
        }).then(({data}) => {
          if (data && data.code === 200) {
            this.dataList = data.data.records
            this.totalPage = data.data.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数量变化
      sizeChangeHandle (val) {
        this.dataForm.pageSize = val
        this.dataForm.pageNum = 1
        this.getDataList()
      },
      // 跳转指定页数
      currentChangeHandle (val) {
        this.dataForm.pageNum = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`是否${id ? '删除' : '批量删除'}?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/admin-interfaces/log/deleteLogs'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 200) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message({
                showClose: true,
                message: data.message,
                type: 'warning',
                center: true
              })
            }
          })
        }).catch(() => {})
      }
    }
  }
</script>
